<?php


namespace app\index\controller;

use app\admin\model\Invite as InviteModel;
class Invite extends Base
{
    public function index()
    {
        $a = InviteModel::where(['status'=>1,'type'=>1])->find();
        $b = InviteModel::where(['status'=>1,'type'=>2])->find();
        $invites = array_merge([$a],[$b]);
        $id = input('type',1);
        $name = InviteModel::where('type',$id)->find();
        $invite = InviteModel::where('type',$id)->select();
        //halt($invite);
        $type = $id;
        return $this->view->fetch('',[
            'type' => $type,
            'id' => $id,
            'name' => $name,
            'invites' => $invites,
            'invite' => $invite,
        ]);
    }

    public function details()
    {
        $a = InviteModel::where(['status'=>1,'type'=>1])->find();
        $b = InviteModel::where(['status'=>1,'type'=>2])->find();
        $invites = array_merge([$a],[$b]);
        $id = input('id');
        $cate = input('type',2);
        $invite = InviteModel::find($id);
        //halt($invite);
        $type = $id;
        $upper = InviteModel::where('id', '<', $id)
            ->where('type',$cate)
            ->where('status', 1)
            ->order('id desc')
            ->find();   //上一条
        $lower = InviteModel::where('id', '>', $id)
            ->where('type',$cate)
            ->where('status', 1)
            ->order('id asc')
            ->find();   //下一条
        return $this->view->fetch('',[
            'type' => $type,
            'id' => $id,
            'upper' => $upper,
            'lower' => $lower,
            'invite' => $invite,
            'invites' => $invites,
        ]);
    }
}